package org.brakepedal.server.support.bluetooth;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;

/**
 * Date: 2024/4/3 15:39
 *
 * @author Huanyu Mark
 */
public class DefaultBtFrameEncoder implements BtFrameEncoder{
    private final ByteBuffer buffer = ByteBuffer.allocate(3);

    {
        Arrays.fill(buffer.array(), ((byte) 0xff));
    }
    @Override
    public void encode(OutputStream out, BtFrame frame) throws IOException {
        if(!(frame instanceof BrakePedalStateFrame stateFrame)) {
            return;
        }
        try {
//            buffer.putInt(BrakePedalStateFrame.HEAD)
//                    .putInt(stateFrame.getAcc())
//                    .putInt(stateFrame.getPressure())
//                    .putInt(stateFrame.getYear())
//                    .putInt(stateFrame.getMonth())
//                    .putInt(stateFrame.getDay())
//                    .putInt(stateFrame.getHour())
//                    .putInt(stateFrame.getMinute())
//                    .putInt(stateFrame.getSecond())
//                    .putInt(BrakePedalStateFrame.TAIL);
            out.write(buffer.array());
        } catch (Exception e) {
            buffer.clear();
        }
    }
}
